package cn.com.jtang.wedding.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.dao.HistoryDao;
import cn.com.jtang.wedding.model.History;

public class HistoryDaoImpl extends BaseDaoImpl implements HistoryDao {
	private static final String ID = "id";
	private static final String COUNT = "count";
	private static final String PRICE = "price";
	private static final String TIME = "time";
	private static final String PARENTID = "parentId";
	private static final String USERID = "userId";
	
	@Override
	public List insertModelToList(Object object) {
		History history = (History)object;
		List args = new ArrayList();
		args.add(0);
		args.add(history.getCount());	
		args.add(history.getPrice());
		args.add(history.getTime());
		args.add(history.getParentId());
		args.add(history.getUserId());
		return args;
	}

	@Override
	public Object resultMapper(ResultSet rs, int rowNum) throws SQLException {
		History history = new History();
		history.setId(rs.getLong(ID));
		history.setCount(rs.getDouble(COUNT));
		history.setPrice(rs.getDouble(PRICE));
		history.setTime(rs.getDate(TIME));
		history.setParentId(rs.getLong(PARENTID));
		history.setUserId(rs.getLong(USERID));
		return history;
	}

	@Override
	public Map updateModelToMap(Object object) {
		History history = (History)object;
		Map map = new HashMap();
		map.put(ID, history.getId());
		map.put(COUNT, history.getCount());
		map.put(PRICE, history.getPrice());
		map.put(TIME, history.getTime());
		map.put(PARENTID, history.getParentId());
		map.put(USERID, history.getUserId());
		return map;
	}
	

	public String insert(History history){
		return super.insert(history);
	}
	
	public History queryById(Long id){
		return (History)super.queryById(id);
	}
	
	public int updateById(Long id, History history) {
		return super.updateById(id, history);
	}
	
	public int deleteById(Long id) {
		return super.deleteById(id);
	}
	
	public List queryAll(Map<String, Object> map, int start,int end, String... orderByStr){
		return super.queryAll(map, start, end, orderByStr);
	}

}
